package sword;

/**
 * @Author: 海琳琦
 * @Date: 2022/5/25 18:38
 */
public class Title21 {

    public static int[] exchange(int[] nums) {
        int left = 0, right = nums.length - 1;
        while (left < right) {
            //左边为奇数
            while (left < right && nums[left] % 2 != 0) {
                //找寻right的位置
                left++;
            }
            //右边为偶数
            while (left < right && nums[right] % 2 == 0) {
                right--;
            }
            int temp = nums[right];
            nums[right] = nums[left];
            nums[left] = temp;
            left++;
            right--;
        }
        return nums;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,3,4};
        exchange(nums);

    }
}
